﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;

namespace NormalGsearch
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, IGsearchView
    {
        private event EventHandler ViewLoaded;
        private event EventHandler ViewClosed;

        private static string ErrorReleaseNotesFileMissing = "ReleaseNotes file is missing!";
        private static string ErrorCaption = "normalGsearch Error";

        public MainWindow()
        {
            InitializeComponent();            
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (ViewLoaded != null)
            {
                ViewLoaded(this, EventArgs.Empty);
            }
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            if (ViewClosed != null)
            {
                ViewClosed(this, EventArgs.Empty);
            }
        }

        event EventHandler IGsearchView.ViewLoaded
        {
            add { ViewLoaded += value; }
            remove { ViewLoaded -= value; }
        }

        event EventHandler IGsearchView.ViewClosed
        {
            add { ViewClosed += value; }
            remove { ViewClosed -= value; }
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            string assemblyLocation = System.Reflection.Assembly.GetAssembly(typeof(MainWindow)).Location;
            string argument = Path.GetDirectoryName(assemblyLocation) + @"\Resources\ReleaseNotes.txt";
            if(File.Exists(argument))
            {
                Process.Start("notepad.exe", argument);
            }
            else
            {                
                MessageBox.Show(ErrorReleaseNotesFileMissing, ErrorCaption, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
    }
}
